/*
题目链接:https://leetcode.cn/problems/count-the-hidden-sequences/?envType=daily-question&envId=2025-04-21
*/

//题解代码:
class Solution {
public:
    #define ll long long
    //diff[0] = hid[1] - hid[0] -----> hid[0] = hid[1] - diff[0]
    //diff[1] = hid[2] - hid[1] -----> hid[0] = hid[2] - diff[1] - diff[0]
    int numberOfArrays(vector<int>& differences, int lower, int upper) {
        int n = differences.size();
        ll sum = 0;
        ll l = lower, r = upper;
        for(auto& x : differences){
            sum += x;
            l = max(l,lower+sum);
            r = min(r,upper+sum);
        }
        return max(0LL,r-l+1);
    }
};
